package com.hnevc.javathreaddemo;

import android.icu.util.Calendar;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    TextView mTvCount ;
    int i=5;
    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            mTvCount.setText(i+"");
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTvCount = (TextView) findViewById(R.id.id_tv_count);
        new Thread(new Runnable() {
            @Override
            public void run() {
                // TODO: 2017/10/25  线程中要做耗时的事情
                while (i>0) {
                    try {
                        Thread.sleep(1000);
                        Log.e("ThreadSleep", "run: " + (i--));
                        handler.sendEmptyMessage(0);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        }).start();
    }
    class MyThread2 implements Runnable{
        @Override
        public void run() {
            // TODO: 2017/10/25 线程中要做耗时的事情
        }
    }

    class MyThread extends Thread{
        @Override
        public void run() {
            // TODO: 2017/10/25 线程中要做耗时的事情
        }
    }
}
